package cn.stu.system.controller;


import cn.stu.common.utils.ApiData;
import cn.stu.framework.dto.RoleDto;
import cn.stu.framework.entity.Role;
import cn.stu.framework.service.RoleService;
import cn.stu.system.annotation.LogAnnotation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * 角色控制器
 *
 * @author 郑志豪
 * @date 2023/09/18
 */
@RestController
@RequestMapping("/role")
public class RoleController {
    /**
     * 服务
     */
    @Autowired
    private RoleService service;


    /**
     * 列表
     *
     * @param dto DTO
     * @return {@link ApiData}
     */
    @RequestMapping(value = "/list")
    public ApiData list(RoleDto dto) {
        return service.roleList(dto);
    }

    /**
     * 德尔
     *
     * @param roleId 角色ID
     * @return {@link ApiData}
     */
    @LogAnnotation("删除角色")
    @RequestMapping(value = "/del", method = RequestMethod.DELETE)
    public ApiData del(@RequestParam("roleId") Long roleId) {
        return service.roleDel(roleId);
    }


    /**
     * 信息
     *
     * @param roleId 角色ID
     * @return {@link ApiData}
     */
    @RequestMapping(value = "/info", method = RequestMethod.GET)
    public ApiData info(@RequestParam(value = "roleId", required = false) Long roleId) {
        return service.roleInfo(roleId);
    }

    /**
     * 添加
     *
     * @param rs RS
     * @return {@link ApiData}
     */
    @LogAnnotation("添加角色")
    @PostMapping(value = "/add")
    public ApiData add(@RequestBody Role rs) {
        return service.roleAdd(rs);
    }

    /**
     * 更新
     *
     * @param rs RS
     * @return {@link ApiData}
     */
    @LogAnnotation("修改角色")
    @RequestMapping(value = "/update", method = RequestMethod.PUT)
    public ApiData update(@RequestBody Role rs) {
        return service.roleUpdate(rs);
    }
}

